package postwp.controller;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import data.Data;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RegisterServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		try {
			req.getRequestDispatcher("/register.jsp").forward(req, resp);
		} catch (Exception localException) {
		}
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		DBCollection coll = Data.data("users");
		BasicDBObject obj = new BasicDBObject();
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		String domain = req.getParameter("domain");
		String user_login = req.getParameter("user_login");
		String pwd_login = req.getParameter("pwd_login");

		obj.put("username", username);
		obj.put("password", password);
		obj.put("url", domain);
		obj.put("user_login", user_login);
		obj.put("pwd_login", pwd_login);

		coll.insert(new DBObject[] { obj });
		resp.sendRedirect("/login");
	}
}